<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">

		<p:growl id="growlPayment" showDetail="false" globalOnly="true" life="6000" autoUpdate="true" />
		<p:dialog header="#{msg.header_add_payment}" widgetVar="newPaymentModal" modal="true"
			resizable="false" width="300" id="newPaymentModal" height="auto">
			
			<h:panelGrid columns="1" id="newPaymentMainPanel">
				<h:form id="formNewPayment">
					<p:row>
						<p:outputLabel value="#{msg.label_type_of_payment}" styleClass="labelsPanelGrid" />
					</p:row>

					<p:row>
						<p:selectOneMenu id="typeOfPayment" value="#{addPaymentController.movimentacaoCaixa.tipoMovimentacao.id}" >
							<f:selectItem itemLabel="#{msg.select_type_of_payment}" itemValue="" />
							<p:ajax update="formNewPayment" listener="#{addPaymentController.typeOfPaymentChanged}" event="change" />
							<f:selectItems itemValue="#{model.id}" var="model" itemLabel="#{model.descricao}" value="#{addPaymentController.listOfTypeOfPayment}"/>
						</p:selectOneMenu>
					</p:row>
					
					<!-- Field Description  -->
					<p:row rendered="#{addPaymentController.descriptionRendered}">
						<p:outputLabel value="#{msg.label_description}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row rendered="#{addPaymentController.descriptionRendered}">
						<p:inputText value="#{addPaymentController.movimentacaoCaixa.descricao}" styleClass="labelsPanelGrid" />
					</p:row>
					
					<!-- Field Value -->
					<p:row rendered="#{addPaymentController.valueRendered}">
						<p:outputLabel value="#{msg.label_value}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row rendered="#{addPaymentController.valueRendered}">
						<p:inputText value="#{addPaymentController.movimentacaoCaixa.valor}" styleClass="labelsPanelGrid" />
					</p:row>
					
					<!-- Field Personal value -->
					<p:row rendered="#{addPaymentController.personalValueRendered}">
						<p:outputLabel value="#{msg.label_personal_value}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row rendered="#{addPaymentController.personalValueRendered}">
						<p:inputText value="#{addPaymentController.personalValue}" styleClass="labelsPanelGrid" />
					</p:row>
					
					<!-- Field date of payment -->
					<p:row rendered="#{addPaymentController.dateOfPaymentRendered}">
						<p:outputLabel value="#{msg.label_date_payment}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row rendered="#{addPaymentController.dateOfPaymentRendered}">
						<p:calendar value="#{addPaymentController.movimentacaoCaixa.data}" styleClass="labelsPanelGrid" > 
							<p:ajax event="dateSelect" update="endPeriodFree" 
									listener="#{addPaymentController.dateOfPaymentChanged}" />
						</p:calendar>
					</p:row>
					
					<!-- Field free until -->
					<p:row rendered="#{addPaymentController.endPeriodFreeRendered}">
						<p:outputLabel value="#{msg.label_end_period_free}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row rendered="#{addPaymentController.endPeriodFreeRendered}">
						<p:calendar id="endPeriodFree" value="#{addPaymentController.endPeriodFree}" styleClass="labelsPanelGrid" 
									mindate="#{addPaymentController.movimentacaoCaixa.data}" />
					</p:row>
					
					<!-- Field way of payment -->
					<p:row rendered="#{addPaymentController.wayOfPaymentRendered}">
						<p:outputLabel value="#{msg.label_way_of_payment}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row rendered="#{addPaymentController.wayOfPaymentRendered}">
						<p:selectOneMenu id="wayOfPayment" value="#{addPaymentController.movimentacaoCaixa.formaPagamento.id}" >
							<f:selectItem itemLabel="#{msg.select_way_of_payment}" itemValue="" />
							<p:ajax update="formNewPayment,:formPaymentByCreditCard" listener="#{addPaymentController.wayOfPaymentChanged}" event="change" />
							<f:selectItems itemValue="#{model.id}" var="model" itemLabel="#{model.descricao}" value="#{addPaymentController.listOfWayOfPayment}"/>
						</p:selectOneMenu>
					</p:row>
					
					<!-- Button Add Cheque -->
					<p:row rendered="#{addPaymentController.paymentByChequeRendered}">
						<p:commandButton value="#{msg.button_add_cheque}" 
										 onclick="PF('addCheque').show();" action="#{addPaymentController.openAddCheque}" update=":formAddCheque" />
					</p:row>
					
					<p:dataTable id="tableCheques" var="cheque" value="#{addPaymentController.movimentacaoCaixa.cheques}" 
								 rendered="#{addPaymentController.paymentByChequeRendered}" rows="10" >
						
						<p:column headerText="#{msg.label_cheque}" style="text-align:center">
							<h:outputText value="#{cheque.numeroCheque}" />
						</p:column>
						
						<p:column headerText="#{msg.label_good_for}" style="text-align:center">
							<h:outputText value="#{cheque.bomPara}">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputText>
						</p:column>
					</p:dataTable>
					
					
					<!-- Table payment By credit card -->					
					<p:dataTable id="tablePaymentsByCreditCard" var="payment" value="#{addPaymentController.pagamentoCartao.parcelaPagamentos}" 
								 rendered="#{addPaymentController.paymentByCreditCard}" rows="10" >
						
						<p:column headerText="#{msg.header_value_of_payment}" style="text-align:center">
							<h:outputText value="#{payment.valor}" />
						</p:column>
						
						<p:column headerText="#{msg.header_vencimento}" style="text-align:center">
							<h:outputText value="#{payment.vencimento}">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputText>
						</p:column>
					</p:dataTable>
					
					<p:row style="display:block;"></p:row>
					
					
					
					<!-- Button save -->
					<p:row rendered="#{addPaymentController.buttonSaveRendered}">
						<p:commandButton value="#{msg.button_save}" action="#{addPaymentController.savePayment}" oncomplete="PF('newPaymentModal').hide();" />
					</p:row>
					
				</h:form>
 			</h:panelGrid>
		</p:dialog>
		
		
		
		
		<!-- Panel Payment by Cheque -->
		<p:growl id="growlAddCheque" showDetail="false" globalOnly="true" life="6000" autoUpdate="true" />
		<p:dialog header="#{msg.header_add_cheque}" widgetVar="addCheque" modal="true"
			resizable="false" width="300" id="addCheque" height="auto">
			
			<h:panelGrid columns="1" id="newPanelAddCheque">
				<h:form id="formAddCheque">
					<!-- Field Cheque Number -->
					<p:row>
						<p:outputLabel value="#{msg.label_cheque_number}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row>
						<p:inputText value="#{addPaymentController.cheque.numeroCheque}" styleClass="labelsPanelGrid" />
					</p:row>
					
					<!-- Field Bank -->
					<p:row>
						<p:outputLabel value="#{msg.label_bank}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row>
						<p:selectOneMenu id="bankCheque" value="#{addPaymentController.cheque.banco.id}" >
							<f:selectItem itemLabel="#{msg.select_bank}" itemValue="" />
							<f:selectItems itemValue="#{model.id}" var="model" itemLabel="#{model.nome}" value="#{addPaymentController.listOfBanks}"/>
						</p:selectOneMenu>
					</p:row>
						
					<!-- Field Agency -->
					<p:row>
						<p:outputLabel value="#{msg.label_agency}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row>
						<p:inputText value="#{addPaymentController.cheque.agencia}" styleClass="labelsPanelGrid" />
					</p:row>
						
					<!-- Field Account -->
					<p:row>
						<p:outputLabel value="#{msg.label_account}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row>
						<p:inputText value="#{addPaymentController.cheque.conta}" styleClass="labelsPanelGrid" />
					</p:row>
						
					<!-- Field Value for cheque -->
					<p:row>
						<p:outputLabel value="#{msg.label_value}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row>
						<p:inputText value="#{addPaymentController.cheque.valor}" styleClass="labelsPanelGrid" />
					</p:row>
						
					<!-- Field good for? -->
					<p:row>
						<p:outputLabel value="#{msg.label_good_for}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row>
						<p:calendar value="#{addPaymentController.cheque.bomPara}" styleClass="labelsPanelGrid" ></p:calendar>
					</p:row>
					
					<!-- Button save Cheque -->
					<p:row>
						<p:commandButton value="#{msg.button_save_cheque}" action="#{addPaymentController.saveCheque}" 
										 oncomplete="PF('addCheque').hide();" update=":formNewPayment" />
					</p:row>
					
				</h:form>
			</h:panelGrid>
		</p:dialog>
		
		
		
		<!-- Panel Payment by Credit Card -->
		<p:growl id="growlCreditCard" showDetail="false" globalOnly="true" life="6000" autoUpdate="true" />
		<p:dialog header="#{msg.header_payment_by_credit_card}" widgetVar="dialogCreditCard" modal="true"
			resizable="false" width="300" id="dialogCreditCard" height="auto">
			
			<h:panelGrid columns="1" id="newPanelByCreditCard">
				<h:form id="formPaymentByCreditCard">
					
					<!-- Field Credit Card Carrier -->
					<p:row>
						<p:outputLabel value="#{msg.label_credit_card_carrier}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row>
						<p:selectOneMenu id="creditCardCarrier" value="#{addPaymentController.pagamentoCartao.operadoraCartao.id}" >
							<f:selectItem itemLabel="#{msg.select_credit_card_carrier}" itemValue="" />
							<f:selectItems itemValue="#{model.id}" var="model" itemLabel="#{model.nome}" value="#{addPaymentController.listOfCreditCardCarrier}"/>
						</p:selectOneMenu>
					</p:row>
					
					<!-- Field number of Plots (Parcelas) -->
					<p:row>
						<p:outputLabel value="#{msg.label_number_of_plots}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row>
						<p:inputText value="#{addPaymentController.pagamentoCartao.numeroParcela}" styleClass="labelsPanelGrid" />
					</p:row>
					
					<!-- Field day Vencimento da Fatura -->
					<p:row>
						<p:outputLabel value="#{msg.label_day_of_payment_for_credit_card}" styleClass="labelsPanelGrid" />
					</p:row>
					<p:row>
						<p:selectOneMenu id="dayOfPaymentForCreditCard" value="#{addPaymentController.diaPagamentoFaturaCartao}" >
							<f:selectItem itemLabel="#{msg.select_day_of_payment_for_credit_card}" itemValue="" />
							<f:selectItems itemValue="#{model}" var="model" itemLabel="#{model}" value="#{addPaymentController.listDiaVencimentoFaturaCartao}"/>
						</p:selectOneMenu>
					</p:row>
					
					<!-- Button save Payment By Cheque -->
					<p:row>
						<p:commandButton value="#{msg.button_save_payment_by_credit_card}" action="#{addPaymentController.addPaymentByCreditCard}" 
										 oncomplete="PF('dialogCreditCard').hide();" update=":formNewPayment" />
					</p:row>
					
				</h:form>
			</h:panelGrid>
		</p:dialog>
</ui:composition>
